package com.gsm.phimhanhdong;

import java.io.IOException;
import java.io.InputStream;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.util.Log;

public class HttpHelper {

	public static final String TAG = "HttpHelper";
	
	public static String get(String url_request) {
		String result = "";
		Log.e(TAG, url_request);
		HttpGet httpGet = new HttpGet(url_request);
		HttpClient client = new DefaultHttpClient();
		HttpResponse response;
		try {
			response = client.execute(httpGet);
			Log.e("", "res status " + response.toString());
//			if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
				InputStream inputStream = response.getEntity().getContent();
				result = CommonUtils.inputStreamToString(inputStream);
				Log.e(TAG, result);
				client.getConnectionManager().shutdown();
				client = null;
				return result;
//			}
		} catch (ClientProtocolException e) {
			e.printStackTrace();
			client.getConnectionManager().shutdown();
			client = null;
		} catch (IOException e) {
			e.printStackTrace();
			client.getConnectionManager().shutdown();
			client = null;
		}
		Log.d(TAG, result);
		return result;
	}

	

}
